Knot Removal

Test Cases for the Procedure RemoveKnot and CleanKnots

1) The first test of the knot removal algorithms is the case given in The NURBS Book's Figure 5.27.

Figure 5.27

The following program tests the knot removal algorithm for curves by reproducing the case demonstrated above.

program test_curve_knot_removal

use splines
use points

implicit none

integer, parameter :: wp  = selected_real_kind(15,307)
logical, parameter :: T = .true.
logical, parameter :: F = .false.
type(curve) :: c, c2, c3, c4, c5
type(cpt) :: cp(10)
real(wp) :: U(14)

! CPs are relatively exact
cp(:)%x = [0.013_wp, -0.222_wp, 0.904_wp, 2.699_wp, 3.326_wp, 3.959_wp, 4.522_wp, 5.230_wp,  5.056_wp,  7.587_wp]
cp(:)%y = [0.006_wp,  1.423_wp, 3.179_wp, 3.575_wp, 3.509_wp, 3.431_wp, 3.128_wp, 1.588_wp, -0.015_wp, -0.006_wp]

U = [0.0_wp,0.0_wp,0.0_wp,0.0_wp,0.30_wp,0.50_wp,0.50_wp,0.50_wp,0.70_wp,0.70_wp,1.0_wp,1.0_wp,1.0_wp,1.0_wp]

c = spl(dim=2, pd=1, p=[3], kXi=U, cp=cp)

call c%plot(plotCP=T, labelCP=T,                              &
                terminal='png', fname="test_F5.27a",    &
                title="Figure 5.27(a). The original cubic curve defined over the&
                                     & knot vector \\{0, 0, 0, 0, 0.3, 0.5, 0.5, 0.5, 0.7, 0.7, 1, 1, 1, 1\\}.")

c2 = c
call c2%RemoveKnot(u=0.30_wp,num=1,tol=0.07_wp)
call plot(  me=[c,c2], plotCP=T,            &
            terminal='png', fname="test_F5.27b",    &
            title="Figure 5.27(b). Removal of 0.3, one time.")

c3 = c
call c3%RemoveKnot(u=0.50_wp,num=1,tol=0.07_wp)
call plot(  me=[c,c3], plotCP=T,            &
            terminal='png', fname="test_F5.27c",    &
            title="Figure 5.27(c). Removal of 0.5, one time.")

c4 = c
call c4%RemoveKnot(u=0.50_wp,num=2,tol=0.07_wp)
call plot(  me=[c,c4], plotCP=T,            &
            terminal='png', fname="test_F5.27d",    &
            title="Figure 5.27(d). Removal of 0.5, two time.")

c5 = c
call c5%RemoveKnot(u=0.50_wp,num=3,tol=0.07_wp)
call plot(  me=[c,c5], plotCP=T,            &
            terminal='png', fname="test_F5.27e",    &
            title="Figure 5.27(e). Removal of 0.5, three time.")

pause
end program test_curve_knot_removal

The resulting plots is as follow,


Figure 5.27(a)
Figure 5.27(b)
Figure 5.27(c)
Figure 5.27(d)
Figure 5.27(e)


2) The second example test the algorithm for removing as many knots as possible from a curve knot vector by reproducing the case given in The NURBS Book's Figure 5.29.

Figure 5.29

program test_curve_knot_removal_all

use splines
use points

implicit none

integer, parameter :: wp  = selected_real_kind(15,307)
logical, parameter :: T = .true.
logical, parameter :: F = .false.
type(curve) :: c, c2, c3, c4, c5, c6
type(cpt) :: cp(11)
real(wp) :: U(15)

! CPs are relatively exact
cp(:)%x = [0.589_wp, 4.716_wp, 8.826_wp, 10.411_wp, 14.612_wp, 19.433_wp, 23.136_wp, 24.805_wp, 22.498_wp, 17.001_wp, 12.916_wp]
cp(:)%y = [0.553_wp, 0.530_wp, 3.803_wp, 11.480_wp, 14.567_wp, 14.710_wp, 12.346_wp, 7.698_wp, 3.875_wp, 2.651_wp, 2.673_wp]
!cp(:)%x = [0.025_wp, 0.183_wp, 0.341_wp, 0.404_wp, 0.567_wp, 0.751_wp, 0.714_wp, 0.480_wp, 0.695_wp, 0.658_wp, 0.501_wp]
!cp(:)%y = [0.166_wp, 0.164_wp, 0.285_wp, 0.577_wp, 0.695_wp, 0.701_wp, 0.490_wp, 0.217_wp, 0.233_wp, 0.244_wp, 0.245_wp]
!cp(:)%w = [1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp, 0.800_wp, 0.500_wp, 0.800_wp, 1.000_wp, 1.000_wp]

cp=0.18217546*cp
U = [0.0_wp,0.0_wp,0.0_wp,0.0_wp, 0.16_wp, 0.31_wp, 0.45_wp, 0.5501_wp,0.702_wp,0.80_wp,0.901_wp,1.0_wp,1.0_wp,1.0_wp,1.0_wp]

c = spl(dim=2, pd=1, p=[3], kXi=U, cp=cp)!, rat=T)

call c%plot(plotCP=T, labelCP=T,                              &
                terminal='png', fname="test_F5.29a",    &
                title="Figure 5.29(a). The original curve defined over &
    & \\{0, 0, 0, 0, 0.16, 0.31, 0.45, 0.5501, 0.702, 0.8, 0.901, 1, 1, 1, 1\\}"      )

c2 = c
call c2%CleanKnots(tol=0.007_wp)
call plot(  me=[c,c2], plotCP=T,            &
            terminal='png', fname="test_F5.29b",    &
            title="Figure 5.29(b). All removable knots are removed by using the tolerance 0.007"      )

c3 = c
call c3%CleanKnots(tol=0.025_wp)
call plot(  me=[c,c3], plotCP=T,            &
            terminal='png', fname="test_F5.29c",    &
            title="Figure 5.29(c). All removable knots are removed by using the tolerance 0.025"      )

c4 = c
call c4%CleanKnots(tol=0.07_wp)
call plot(  me=[c,c4], plotCP=T,            &
            terminal='png', fname="test_F5.29d",    &
            title="Figure 5.29(d). All removable knots are removed by using the tolerance 0.07"      )


c5 = c
call c5%CleanKnots(tol=0.6_wp)
call plot(  me=[c,c5], plotCP=T,            &
            terminal='png', fname="test_F5.29e",    &
            title="Figure 5.29(e). All removable knots are removed by using the tolerance 0.6"      )

c6 = c
call c6%CleanKnots(tol=1.2_wp)
call plot(  me=[c,c5], plotCP=T,            &
            terminal='png', fname="test_F5.29f",    &
            title="Figure 5.29(f). All removable knots are removed by using the tolerance 1.2"      )

pause
end program test_curve_knot_removal_all

3) The third test "surface removal"

4) The third test "surface clean up"

program test_

use splines
use points

implicit none

integer, parameter :: wp  = selected_real_kind(15,307)
logical, parameter :: T = .true.
logical, parameter :: F = .false.
type(spl) :: surface
type(spl), allocatable :: segments(:,:)
type(cpt) :: scp(20)
real(wp) :: U(9), V(7)

scp(:)%x = [ 1.0,  1.0,  1.0,  1.0,  1.0,  0.2,  0.2,  0.2,  0.2,  0.2, &
   -0.2, -0.2, -0.2, -0.2, -0.2, -1.0, -1.0, -1.0, -1.0, -1.0]
scp(:)%y = [-1.0, -0.3,  0.0,  0.7,  1.0, -1.0, -0.3,  0.0,  0.7,  1.0, &
   -1.0, -0.3,  0.0,  0.7,  1.0, -1.0, -0.3,  0.0,  0.7,  1.0]
scp(:)%z = [ 1.0,  1.0, -0.2, -2.0, -2.0,  1.0,  1.0, -0.2, -2.0, -2.0, &
    3.0,  3.0,  2.0,  1.0,  1.0,  3.0,  3.0,  2.0,  1.0,  1.0]

U = [0.0_wp,0.0_wp,0.0_wp,0.0_wp,0.60_wp,1.0_wp,1.0_wp,1.0_wp,1.0_wp]
V = [0.0_wp,0.0_wp,0.0_wp,0.40_wp,1.0_wp,1.0_wp,1.0_wp]

surface = spl(dim=3, pd=2, p=[3,2], kXi=U, kEta=V, cp=scp)

pause
end program test_